//
//  DatabaseCreator.m
//  CC
//
//  Created by Calvin.wang on 3/24/15.
//  Copyright (c) 2015 Calvin. All rights reserved.
//

#import "DatabaseCreator.h"
#import "SQLiteHelper.h"

#ifndef PET_TABLE_QUERY//,USER_TABLE_QUERY,STATUS_TABLE_QUERY

#define PET_TABLE_QUERY @"CREATE TABLE PET (ID integer PRIMARY KEY AUTOINCREMENT,PetID integer NOT NULL, PetName text(128,0),Birthday text(10,0),GenderID, intger, BreedID integer, BreedName text(128,0), Wight_KG integer, Weight_Pound integer, Vattery real DEFAULT 0.5 , DeviceID integer, AutoAcquery integer NOT NULL DEFAULT 0, ModifiedDate text(19,0), UserID integer NOT NULL, PhotoPath text(128,0), ExistsFlag integer)"
#define USEER_TABLE_QUERY @"CREATE TABLE User (Id integer PRIMARY KEY AUTOINCREMENT,name text,screenName text, profileImageUrl text,mbtype text,city text)";
#define STATUS_TABLE_QUERY @"CREATE TABLE Status (Id integer PRIMARY KEY AUTOINCREMENT,source text,createdAt date,\"text\" text,user integer REFERENCES User (Id))";

#endif

@implementation DatabaseCreator

+(void)initDatabase{
    NSString *key=@"IsCreateDb";
    NSUserDefaults *defaults=[[NSUserDefaults alloc]init];
    if ([[defaults valueForKey:key] intValue] !=1) {
        [self createTable];
        [defaults setValue:@1 forKey:key];
    }
}

+(void) createTable{
    NSString *statusSql=STATUS_TABLE_QUERY;
    NSString *userSql=USEER_TABLE_QUERY;
    SQLiteHelper *sqliteHelper=[[SQLiteHelper alloc]init];
    [sqliteHelper executeNonQuery:statusSql];
    [sqliteHelper executeNonQuery:userSql];
}
@end
